package Zoo.Handler;


/*
 *  重要！！（配套Loginview）
 * */

import Zoo.Entity.ZooparkEntity;
import Zoo.Impl.LeaderServiceImpl;
import Zoo.Service.LeaderService;
import Zoo.View.LeaderView.AddZooparkView;
import Zoo.View.LeaderView.LeaderView;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class AddZooparkViewHandler implements ActionListener {
    private AddZooparkView addZooparkView;
    private LeaderView leaderView;
    public AddZooparkViewHandler(AddZooparkView addZooparkView, LeaderView leaderView){
        this.addZooparkView=addZooparkView;
        this.leaderView=leaderView;
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        JButton jButton=(JButton) e.getSource();
        String text =jButton.getText();
        if("添加".equals(text)){

            LeaderService leaderService=new LeaderServiceImpl();
            ZooparkEntity zooparkEntity=addZooparkView.buildZooparkEntity();
            boolean addResult=leaderService.add(zooparkEntity);
            if(addResult){
                //重新加载表格查到最新数据
                leaderView.reloadTable();
                addZooparkView.dispose();
            }else{
                JOptionPane.showMessageDialog(addZooparkView,"添加失败");
            }
        }
    }

}
